﻿namespace ConsoleAppJoin
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            var students = new List<Student>
            {
                new Student { Id = 1, Name = "张三" },
                new Student { Id = 2, Name = "李四" },
                new Student { Id = 3, Name = "王五" },
            };

            var grades = new List<Grade>
            {
                new Grade
                {
                    StudentId = 1,
                    Subject = "数学",
                    Score = 90,
                },
                new Grade
                {
                    StudentId = 2,
                    Subject = "科学",
                    Score = 85,
                },
                new Grade
                {
                    StudentId = 1,
                    Subject = "历史",
                    Score = 88,
                },
            };

            var studentGrades = students.Join(
                grades,
                student => student.Id,
                grade => grade.StudentId,
                (student, grade) =>
                    new
                    {
                        StudentName = student.Name,
                        GradeSubject = grade.Subject,
                        GradeScore = grade.Score,
                    }
            );

            foreach (var sg in studentGrades)
            {
                Console.WriteLine(
                    $"Student: {sg.StudentName}, Subject: {sg.GradeSubject}, Score: {sg.GradeScore}"
                );
            }
        }
    }

    /// <summary>
    /// 学生信息
    /// </summary>
    public class Student
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    /// <summary>
    /// 学生成绩
    /// </summary>
    public class Grade
    {
        public int StudentId { get; set; }

        /// <summary>
        /// 科目
        /// </summary>
        public string Subject { get; set; }

        /// <summary>
        /// 成绩
        /// </summary>
        public int Score { get; set; }
    }
}
